﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PersonalWebsite.Domain.Abstract.Entities.Ability;
using PersonalWebsite.Domain.Abstract.Entities.Enum;

namespace PersonalWebsite.Domain.Abstract.Configuration;

public abstract class BaseConfiguration<TEntity> : IEntityTypeConfiguration<TEntity>
    where TEntity : AudtionEntity
{
    public virtual void Configure(EntityTypeBuilder<TEntity> builder)
    {
        Init(builder);
    }

    private void Init(EntityTypeBuilder<TEntity> builder)
    {
        builder.HasKey(x => x.Id);
        builder.Property(x => x.Id).HasComment("主键").IsRequired().ValueGeneratedOnAdd();

        builder.Property(c => c.DeleteTime).IsRequired(false).HasComment("删除时间");
        builder.Property(c => c.IsDeleted).IsRequired(true).HasComment("删除标识").HasDefaultValue(IsDeletedEnum.N);
        builder.Property(c => c.DeletorId).IsRequired(false).HasComment("删除人");

        builder.Property(c => c.CreateTime).IsRequired(true).HasComment("创建时间")
            .HasDefaultValue(DateTime.Now);
        builder.Property(c => c.CreatorId).IsRequired(true).HasComment("创建人");

        builder.Property(c => c.EditorTime).IsRequired(false).HasComment("编辑时间");
        builder.Property(c => c.EditorId).IsRequired(false).HasComment("编辑人");
    }
}
